home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7819 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How big is the 0
  5. Date: 19 Feb 1996 12:53:30 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4g9rsa$dba@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe6.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 17, 1996 13:24:20 in article <How big is the 0>,
  15. 'anh@kuhub.cc.ukans.edu' wrote: 
  16.  
  17. >In C, anytime I need to do a null pointer check I would do this: 
  18. >    MyType *p; 
  19. >    if(p==(MyType*)0) 
  20. >        bla; 
  21. >The new operator supposedly return a 0 upon failure. Can I rely on the  
  22. >compiler to make sure the 0 is as big as the size of the pointer? For  
  23. >example, ALPHA's pointers are 64 bits long which is different from the 32
  24. bits 
  25. >int. 
  26. Yes, it's guaranteed by the language. 
  27.  
  28. Note that it's not necessary to cast 0 to your type, in fact, I usually 
  29. use the shortcut version: 
  30.     if (p) 
  31.       p->DoStuff(); 
  32.  
  33. Note 2:  Global new operator returning 0 upon failure is going to 
  34. change as the new draft standard specifies that an exception will 
  35. be thrown instead.  As of this date, no commercially available 
  36. compiler on the PC implements this (at least not quite like the 
  37. draft std specifies). 
  38.  
  39. -- 
  40. Pete Grant 
  41. Kalevi, Inc. 
  42. Software Engineering & development
  43.